module.exports = orderDetailController;
orderDetailController.$inject = [
    '$scope',
    '$location',
    //'$routeParams',
    'orderService',
    '$uibModal',
    '$uibModalInstance',
    'orderDetail',
    'refresh',
    '$interval'
]
function orderDetailController($scope, $location, orderSvc,$modal,$uibModalInstance,orderDetail,refresh,$interval){
    $scope.orderDetail = orderDetail;
    let pre = new Date($scope.orderDetail.createDate).valueOf();
    var timer = $interval(function () {
        let cur =  new Date().valueOf();
        $scope.now = new Date(180000-cur+pre);
    }, 1000);
    $scope.cancel = function(){
        $uibModalInstance.dismiss('cancel');
        console.log("modal  close !");
    }
    $scope.receive = function(){
        $scope.orderDetail.status = "商家接单";
        orderSvc.updateOrderInfo($scope.orderDetail,function(err,result){
            if(err){
                console.log(err);
            }else{
                $uibModalInstance.dismiss('cancel');
                //refresh();
            }
        })
    }
    $scope.delivery = function(){
        $scope.orderDetail.status = "正在配送";
        orderSvc.updateOrderInfo($scope.orderDetail,function(err,result){
            if(err){
                console.log(err);
            }else{
                $uibModalInstance.dismiss('cancel');
                //refresh();
            }
        })
    }
   
    $scope.reject = function(){
        $scope.orderDetail.status = "商家拒接";
        orderSvc.updateOrderInfo($scope.orderDetail,function(err,result){
            if(err){
                console.log(err);
            }else{
                $uibModalInstance.dismiss('cancel');
                //refresh();
            }
        })
    }



}

